<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <el-form ref="form" :model="detail" label-width="100px" class="form">
        <!--        预售证相关-->
        <el-form-item label="预售证号">
          <el-input v-model="detail.permitNum" />
        </el-form-item>
        <el-form-item label="发证时间">
          <el-date-picker
            v-model="detail.issuingTime"
            type="datetime"
            placeholder="选择日期"
          />
        </el-form-item>
        <el-form-item label="绑定楼栋">
          <el-input v-model="detail.boundBuilding" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button @click="cancel">返回</el-button>
        </el-form-item>
      </el-form>
    </el-scrollbar>
  </section>
</template>
<script>
import { permitList, permitAdd, permitUpdate, permitDelete } from '@/api/api'
export default {
  data() {
    return {
      developersIdOptions: [],
      detail: {
        'boundBuilding': '',
        'issuingTime': '',
        'permitNum': ''
      }
    }
  },
  created() {
    if (this.$route.query.item) {
      this.detail = JSON.parse(this.$route.query.item)
    }
  },
  methods: {
    getMb() {
      developersList({
        curPage: 1,
        pageSize: 9999,
        name: ''
      }).then(({ data }) => {
        this.developersIdOptions = data.records
      })
    },
    handleRemove(index) {
      this.fileList.splice(index, 1)
    },
    // 上传图片之前的验证
    handleUpload() {
    },
    // 上传成功之后的回调
    handleSuccess(res) {
      if (res.code === 200) {
        this.fileList.push(res.data)
        this.detail.logo = this.fileList[0]
      }
    },
    // 添加/编辑
    submit() {
      // 验证不通过则不提交
      if (!this.vertify()) {
        return false
      }
      const param = JSON.parse(JSON.stringify(this.detail))
      if (this.$route.query.item) {
        // 编辑
        permitUpdate(param).then(data => {
          Is.tip('编辑成功', 2000, 'success')
          this.$router.back()
        })
      } else {
        param.dataId = this.$route.query.dataId
        // 新增
        permitAdd(param).then(data => {
          Is.tip('添加成功', 2000, 'success')
          this.$router.back()
        })
      }
    },
    // 返回
    cancel() {
      this.$router.back()
    },
    vertify() {
      // if (Is.empty(this.detail.title)) {
      //   Is.tip('请输入标题')
      //   return false
      // }
      return true
    }
  }}
</script>
